home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_061 / microemacs / window.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  18KB  |  689 lines

  1. /*
  2.  * Window management. Some of the functions are internal, and some are
  3.  * attached to keys that the user actually types.
  4.  */
  5.  
  6. #include        <stdio.h>
  7. #include        "estruct.h"
  8. #include    "edef.h"
  9.  
  10. #if    MEGAMAX & ST520
  11. overlay    "window"
  12. #endif
  13.  
  14. /*
  15.  * Reposition dot in the current window to line "n". If the argument is
  16.  * positive, it is that line. If it is negative it is that line from the
  17.  * bottom. If it is 0 the window is centered (this is what the standard
  18.  * redisplay code does). With no argument it defaults to 0. Bound to M-!.
  19.  */
  20. reposition(f, n)
  21.     {
  22.     if (f == FALSE)    /* default to 0 to center screen */
  23.     n = 0;
  24.     curwp->w_force = n;
  25.     curwp->w_flag |= WFFORCE;
  26.     return (TRUE);
  27.     }
  28.  
  29. /*
  30.  * Refresh the screen. With no argument, it just does the refresh. With an
  31.  * argument it recenters "." in the current window. Bound to "C-L".
  32.  */
  33. refresh(f, n)
  34.     {
  35.     if (f == FALSE)
  36.         sgarbf = TRUE;
  37.     else
  38.         {
  39.         curwp->w_force = 0;             /* Center dot. */
  40.         curwp->w_flag |= WFFORCE;
  41.         }
  42.  
  43.     return (TRUE);
  44.     }
  45.  
  46. /*
  47.  * The command make the next window (next => down the screen) the current
  48.  * window. There are no real errors, although the command does nothing if
  49.  * there is only 1 window on the screen. Bound to "C-X C-N".
  50.  *
  51.  * with an argument this command finds the <n>th window from the top
  52.  *
  53.  */
  54. nextwind(f, n)
  55.  
  56. int f, n;    /* default flag and numeric argument */
  57.  
  58. {
  59.     register WINDOW *wp;
  60.     register int nwindows;        /* total number of windows */
  61.  
  62.     if (f) {
  63.  
  64.         /* first count the # of windows */
  65.         wp = wheadp;
  66.         nwindows = 1;
  67.         while (wp->w_wndp != NULL) {
  68.             nwindows++;
  69.             wp = wp->w_wndp;
  70.         }
  71.  
  72.         /* if the argument is negative, it is the nth window
  73.            from the bottom of the screen            */
  74.         if (n < 0)
  75.             n = nwindows + n + 1;
  76.  
  77.         /* if an argument, give them that window from the top */
  78.         if (n > 0 && n <= nwindows) {
  79.             wp = wheadp;
  80.             while (--n)
  81.                 wp = wp->w_wndp;
  82.         } else {
  83.             mlwrite("Window number out of range");
  84.             return(FALSE);
  85.         }
  86.     } else
  87.         if ((wp = curwp->w_wndp) == NULL)
  88.             wp = wheadp;
  89.     curwp = wp;
  90.     curbp = wp->w_bufp;
  91.     upmode();
  92.     return (TRUE);
  93. }
  94.  
  95. /*
  96.  * This command makes the previous window (previous => up the screen) the
  97.  * current window. There arn't any errors, although the command does not do a
  98.  * lot if there is 1 window.
  99.  */
  100. prevwind(f, n)
  101. {
  102.     register WINDOW *wp1;
  103.     register WINDOW *wp2;
  104.  
  105.     /* if we have an argument, we mean the nth window from the bottom */
  106.     if (f)
  107.         return(nextwind(f, -n));
  108.  
  109.     wp1 = wheadp;
  110.     wp2 = curwp;
  111.  
  112.     if (wp1 == wp2)
  113.         wp2 = NULL;
  114.  
  115.     while (wp1->w_wndp != wp2)
  116.         wp1 = wp1->w_wndp;
  117.  
  118.     curwp = wp1;
  119.     curbp = wp1->w_bufp;
  120.     upmode();
  121.     return (TRUE);
  122. }
  123.  
  124. /*
  125.  * This command moves the current window down by "arg" lines. Recompute the
  126.  * top line in the window. The move up and move down code is almost completely
  127.  * the same; most of the work has to do with reframing the window, and picking
  128.  * a new dot. We share the code by having "move down" just be an interface to
  129.  * "move up". Magic. Bound to "C-X C-N".
  130.  */
  131. mvdnwind(f, n)
  132.  
  133. int n;
  134.  
  135. {
  136.     return (mvupwind(f, -n));
  137. }
  138.  
  139. /*
  140.  * Move the current window up by "arg" lines. Recompute the new top line of
  141.  * the window. Look to see if "." is still on the screen. If it is, you win.
  142.  * If it isn't, then move "." to center it in the new framing of the window
  143.  * (this command does not really move "."; it moves the frame). Bound to
  144.  * "C-X C-P".
  145.  */
  146. mvupwind(f, n)
  147.     int n;
  148.     {
  149.     register LINE *lp;
  150.     register int i;
  151.  
  152.     lp = curwp->w_linep;
  153.  
  154.     if (n < 0)
  155.         {
  156.         while (n++ && lp!=curbp->b_linep)
  157.             lp = lforw(lp);
  158.         }
  159.     else
  160.         {
  161.         while (n-- && lback(lp)!=curbp->b_linep)
  162.             lp = lback(lp);
  163.         }
  164.  
  165.     curwp->w_linep = lp;
  166.     curwp->w_flag |= WFHARD;            /* Mode line is OK. */
  167.  
  168.     for (i = 0; i < curwp->w_ntrows; ++i)
  169.         {
  170.         if (lp == curwp->w_dotp)
  171.             return (TRUE);
  172.         if (lp == curbp->b_linep)
  173.             break;
  174.         lp = lforw(lp);
  175.         }
  176.  
  177.     lp = curwp->w_linep;
  178.     i  = curwp->w_ntrows/2;
  179.  
  180.     while (i-- && lp != curbp->b_linep)
  181.         lp = lforw(lp);
  182.  
  183.     curwp->w_dotp  = lp;
  184.     curwp->w_doto  = 0;
  185.     return (TRUE);
  186.     }
  187.  
  188. /*
  189.  * This command makes the current window the only window on the screen. Bound
  190.  * to "C-X 1". Try to set the framing so that "." does not have to move on the
  191.  * display. Some care has to be taken to keep the values of dot and mark in
  192.  * the buffer structures right if the distruction of a window makes a buffer
  193.  * become undisplayed.
  194.  */
  195. onlywind(f, n)
  196. {
  197.         register WINDOW *wp;
  198.         register LINE   *lp;
  199.         register int    i;
  200.  
  201.         while (wheadp != curwp) {
  202.                 wp = wheadp;
  203.                 wheadp = wp->w_wndp;
  204.                 if (--wp->w_bufp->b_nwnd == 0) {
  205.                         wp->w_bufp->b_dotp  = wp->w_dotp;
  206.                         wp->w_bufp->b_doto  = wp->w_doto;
  207.                         wp->w_bufp->b_markp = wp->w_markp;
  208.                         wp->w_bufp->b_marko = wp->w_marko;
  209.                 }
  210.                 free((char *) wp);
  211.         }
  212.         while (curwp->w_wndp != NULL) {
  213.                 wp = curwp->w_wndp;
  214.                 curwp->w_wndp = wp->w_wndp;
  215.                 if (--wp->w_bufp->b_nwnd == 0) {
  216.                         wp->w_bufp->b_dotp  = wp->w_dotp;
  217.                         wp->w_bufp->b_doto  = wp->w_doto;
  218.                         wp->w_bufp->b_markp = wp->w_markp;
  219.                         wp->w_bufp->b_marko = wp->w_marko;
  220.                 }
  221.                 free((char *) wp);
  222.         }
  223.         lp = curwp->w_linep;
  224.         i  = curwp->w_toprow;
  225.         while (i!=0 && lback(lp)!=curbp->b_linep) {
  226.                 --i;
  227.                 lp = lback(lp);
  228.         }
  229.         curwp->w_toprow = 0;
  230.         curwp->w_ntrows = term.t_nrow-1;
  231.         curwp->w_linep  = lp;
  232.         curwp->w_flag  |= WFMODE|WFHARD;
  233.         return (TRUE);
  234. }
  235.  
  236. /*
  237.  * Delete the current window, placing its space in the window above,
  238.  * or, if it is the top window, the window below. Bound to C-X 0.
  239.  */
  240.  
  241. delwind(f,n)
  242.  
  243. int f, n;    /* arguments are ignored for this command */
  244.  
  245. {
  246.     register WINDOW *wp;    /* window to recieve deleted space */
  247.     register WINDOW *lwp;    /* ptr window before curwp */
  248.     register int target;    /* target line to search for */
  249.  
  250.     /* if there is only one window, don't delete it */
  251.     if (wheadp->w_wndp == NULL) {
  252.         mlwrite("Can not delete this window");
  253.         return(FALSE);
  254.     }
  255.  
  256.     /* find window before curwp in linked list */
  257.     wp = wheadp;
  258.     lwp = NULL;
  259.     while (wp != NULL) {
  260.         if (wp == curwp)
  261.             break;
  262.         lwp = wp;
  263.         wp = wp->w_wndp;
  264.     }
  265.  
  266.     /* find recieving window and give up our space */
  267.     wp = wheadp;
  268.     if (curwp->w_toprow == 0) {
  269.         /* find the next window down */
  270.         target = curwp->w_ntrows + 1;
  271.         while (wp != NULL) {
  272.             if (wp->w_toprow == target)
  273.                 break;
  274.             wp = wp->w_wndp;
  275.         }
  276.         if (wp == NULL)
  277.             return(FALSE);
  278.         wp->w_toprow = 0;
  279.         wp->w_ntrows += target;
  280.     } else {
  281.         /* find the next window up */
  282.         target = curwp->w_toprow - 1;
  283.         while (wp != NULL) {
  284.             if ((wp->w_toprow + wp->w_ntrows) == target)
  285.                 break;
  286.             wp = wp->w_wndp;
  287.         }
  288.         if (wp == NULL)
  289.             return(FALSE);
  290.         wp->w_ntrows += 1 + curwp->w_ntrows;
  291.     }
  292.  
  293.     /* get rid of the current window */
  294.     if (--curwp->w_bufp->b_nwnd == 0) {
  295.         curwp->w_bufp->b_dotp = curwp->w_dotp;
  296.         curwp->w_bufp->b_doto = curwp->w_doto;
  297.         curwp->w_bufp->b_markp = curwp->w_markp;
  298.         curwp->w_bufp->b_marko = curwp->w_marko;
  299.     }
  300.     if (lwp == NULL)
  301.         wheadp = curwp->w_wndp;
  302.     else
  303.         lwp->w_wndp = curwp->w_wndp;
  304.     free((char *)curwp);
  305.     curwp = wp;
  306.     wp->w_flag |= WFHARD;
  307.     curbp = wp->w_bufp;
  308.     upmode();
  309.     return(TRUE);
  310. }
  311.  
  312. /*
  313.  
  314. Split the current window.  A window smaller than 3 lines cannot be
  315. split.  An argument of 1 forces the cursor into the upper window, an
  316. argument of two forces the cursor to the lower window.  The only other
  317. error that is possible is a "malloc" failure allocating the structure
  318. for the new window.  Bound to "C-X 2". 
  319.  
  320.  */
  321. splitwind(f, n)
  322.  
  323. int f, n;    /* default flag and numeric argument */
  324.  
  325. {
  326.         register WINDOW *wp;
  327.         register LINE   *lp;
  328.         register int    ntru;
  329.         register int    ntrl;
  330.         register int    ntrd;
  331.         register WINDOW *wp1;
  332.         register WINDOW *wp2;
  333.     char *malloc();
  334.  
  335.         if (curwp->w_ntrows < 3) {
  336.                 mlwrite("Cannot split a %d line window", curwp->w_ntrows);
  337.                 return (FALSE);
  338.         }
  339.         if ((wp = (WINDOW *) malloc(sizeof(WINDOW))) == NULL) {
  340.                 mlwrite("Cannot allocate WINDOW block");
  341.                 return (FALSE);
  342.         }
  343.         ++curbp->b_nwnd;                        /* Displayed twice.     */
  344.         wp->w_bufp  = curbp;
  345.         wp->w_dotp  = curwp->w_dotp;
  346.         wp->w_doto  = curwp->w_doto;
  347.         wp->w_markp = curwp->w_markp;
  348.         wp->w_marko = curwp->w_marko;
  349.         wp->w_flag  = 0;
  350.         wp->w_force = 0;
  351. #if    COLOR
  352.     /* set the colors of the new window */
  353.     wp->w_fcolor = gfcolor;
  354.     wp->w_bcolor = gbcolor;
  355. #endif
  356.         ntru = (curwp->w_ntrows-1) / 2;         /* Upper size           */
  357.         ntrl = (curwp->w_ntrows-1) - ntru;      /* Lower size           */
  358.         lp = curwp->w_linep;
  359.         ntrd = 0;
  360.         while (lp != curwp->w_dotp) {
  361.                 ++ntrd;
  362.                 lp = lforw(lp);
  363.         }
  364.         lp = curwp->w_linep;
  365.         if (((f == FALSE) && (ntrd <= ntru)) || ((f == TRUE) && (n == 1))) {
  366.                 /* Old is upper window. */
  367.                 if (ntrd == ntru)               /* Hit mode line.       */
  368.                         lp = lforw(lp);
  369.                 curwp->w_ntrows = ntru;
  370.                 wp->w_wndp = curwp->w_wndp;
  371.                 curwp->w_wndp = wp;
  372.                 wp->w_toprow = curwp->w_toprow+ntru+1;
  373.                 wp->w_ntrows = ntrl;
  374.         } else {                                /* Old is lower window  */
  375.                 wp1 = NULL;
  376.                 wp2 = wheadp;
  377.                 while (wp2 != curwp) {
  378.                         wp1 = wp2;
  379.                         wp2 = wp2->w_wndp;
  380.                 }
  381.                 if (wp1 == NULL)
  382.                         wheadp = wp;
  383.                 else
  384.                         wp1->w_wndp = wp;
  385.                 wp->w_wndp   = curwp;
  386.                 wp->w_toprow = curwp->w_toprow;
  387.                 wp->w_ntrows = ntru;
  388.                 ++ntru;                         /* Mode line.           */
  389.                 curwp->w_toprow += ntru;
  390.                 curwp->w_ntrows  = ntrl;
  391.                 while (ntru--)
  392.                         lp = lforw(lp);
  393.         }
  394.         curwp->w_linep = lp;                    /* Adjust the top lines */
  395.         wp->w_linep = lp;                       /* if necessary.        */
  396.         curwp->w_flag |= WFMODE|WFHARD;
  397.         wp->w_flag |= WFMODE|WFHARD;
  398.         return (TRUE);
  399. }
  400.  
  401. /*
  402.  * Enlarge the current window. Find the window that loses space. Make sure it
  403.  * is big enough. If so, hack the window descriptions, and ask redisplay to do
  404.  * all the hard work. You don't just set "force reframe" because dot would
  405.  * move. Bound to "C-X Z".
  406.  */
  407. enlargewind(f, n)
  408. {
  409.         register WINDOW *adjwp;
  410.         register LINE   *lp;
  411.         register int    i;
  412.  
  413.         if (n < 0)
  414.                 return (shrinkwind(f, -n));
  415.         if (wheadp->w_wndp == NULL) {
  416.                 mlwrite("Only one window");
  417.                 return (FALSE);
  418.         }
  419.         if ((adjwp=curwp->w_wndp) == NULL) {
  420.                 adjwp = wheadp;
  421.                 while (adjwp->w_wndp != curwp)
  422.                         adjwp = adjwp->w_wndp;
  423.         }
  424.         if (adjwp->w_ntrows <= n) {
  425.                 mlwrite("Impossible change");
  426.                 return (FALSE);
  427.         }
  428.         if (curwp->w_wndp == adjwp) {           /* Shrink below.        */
  429.                 lp = adjwp->w_linep;
  430.                 for (i=0; i<n && lp!=adjwp->w_bufp->b_linep; ++i)
  431.                         lp = lforw(lp);
  432.                 adjwp->w_linep  = lp;
  433.                 adjwp->w_toprow += n;
  434.         } else {                                /* Shrink above.        */
  435.                 lp = curwp->w_linep;
  436.                 for (i=0; i<n && lback(lp)!=curbp->b_linep; ++i)
  437.                         lp = lback(lp);
  438.                 curwp->w_linep  = lp;
  439.                 curwp->w_toprow -= n;
  440.         }
  441.         curwp->w_ntrows += n;
  442.         adjwp->w_ntrows -= n;
  443.         curwp->w_flag |= WFMODE|WFHARD;
  444.         adjwp->w_flag |= WFMODE|WFHARD;
  445.         return (TRUE);
  446. }
  447.  
  448. /*
  449.  * Shrink the current window. Find the window that gains space. Hack at the
  450.  * window descriptions. Ask the redisplay to do all the hard work. Bound to
  451.  * "C-X C-Z".
  452.  */
  453. shrinkwind(f, n)
  454. {
  455.         register WINDOW *adjwp;
  456.         register LINE   *lp;
  457.         register int    i;
  458.  
  459.         if (n < 0)
  460.                 return (enlargewind(f, -n));
  461.         if (wheadp->w_wndp == NULL) {
  462.                 mlwrite("Only one window");
  463.                 return (FALSE);
  464.         }
  465.         if ((adjwp=curwp->w_wndp) == NULL) {
  466.                 adjwp = wheadp;
  467.                 while (adjwp->w_wndp != curwp)
  468.                         adjwp = adjwp->w_wndp;
  469.         }
  470.         if (curwp->w_ntrows <= n) {
  471.                 mlwrite("Impossible change");
  472.                 return (FALSE);
  473.         }
  474.         if (curwp->w_wndp == adjwp) {           /* Grow below.          */
  475.                 lp = adjwp->w_linep;
  476.                 for (i=0; i<n && lback(lp)!=adjwp->w_bufp->b_linep; ++i)
  477.                         lp = lback(lp);
  478.                 adjwp->w_linep  = lp;
  479.                 adjwp->w_toprow -= n;
  480.         } else {                                /* Grow above.          */
  481.                 lp = curwp->w_linep;
  482.                 for (i=0; i<n && lp!=curbp->b_linep; ++i)
  483.                         lp = lforw(lp);
  484.                 curwp->w_linep  = lp;
  485.                 curwp->w_toprow += n;
  486.         }
  487.         curwp->w_ntrows -= n;
  488.         adjwp->w_ntrows += n;
  489.         curwp->w_flag |= WFMODE|WFHARD;
  490.         adjwp->w_flag |= WFMODE|WFHARD;
  491.         return (TRUE);
  492. }
  493.  
  494. /*    Resize the current window to the requested size    */
  495.  
  496. resize(f, n)
  497.  
  498. int f, n;    /* default flag and numeric argument */
  499.  
  500. {
  501.     int clines;    /* current # of lines in window */
  502.     
  503.     /* must have a non-default argument, else ignore call */
  504.     if (f == FALSE)
  505.         return(TRUE);
  506.  
  507.     /* find out what to do */
  508.     clines = curwp->w_ntrows;
  509.  
  510.     /* already the right size? */
  511.     if (clines == n)
  512.         return(TRUE);
  513.  
  514.     return(enlargewind(TRUE, n - clines));
  515. }
  516.  
  517. /*
  518.  * Pick a window for a pop-up. Split the screen if there is only one window.
  519.  * Pick the uppermost window that isn't the current window. An LRU algorithm
  520.  * might be better. Return a pointer, or NULL on error.
  521.  */
  522. WINDOW  *
  523. wpopup()
  524. {
  525.         register WINDOW *wp;
  526.  
  527.         if (wheadp->w_wndp == NULL              /* Only 1 window        */
  528.         && splitwind(FALSE, 0) == FALSE)        /* and it won't split   */
  529.                 return (NULL);
  530.         wp = wheadp;                            /* Find window to use   */
  531.         while (wp!=NULL && wp==curwp)
  532.                 wp = wp->w_wndp;
  533.         return (wp);
  534. }
  535.  
  536. scrnextup(f, n)        /* scroll the next window up (back) a page */
  537.  
  538. {
  539.     nextwind(FALSE, 1);
  540.     backpage(f, n);
  541.     prevwind(FALSE, 1);
  542. }
  543.  
  544. scrnextdw(f, n)        /* scroll the next window down (forward) a page */
  545.  
  546. {
  547.     nextwind(FALSE, 1);
  548.     forwpage(f, n);
  549.     prevwind(FALSE, 1);
  550. }
  551.  
  552. savewnd(f, n)        /* save ptr to current window */
  553.  
  554. {
  555.     swindow = curwp;
  556.     return(TRUE);
  557. }
  558.  
  559. restwnd(f, n)        /* restore the saved screen */
  560.  
  561. {
  562.     register WINDOW *wp;
  563.  
  564.     /* find the window */
  565.     wp = wheadp;
  566.     while (wp != NULL) {
  567.         if (wp == swindow) {
  568.             curwp = wp;
  569.             curbp = wp->w_bufp;
  570.             upmode();
  571.             return (TRUE);
  572.         }
  573.         wp = wp->w_wndp;
  574.     }
  575.  
  576.     mlwrite("[No such window exists]");
  577.     return(FALSE);
  578. }
  579.  
  580. newsize(f, n)    /* resize the screen, re-writing the screen */
  581.  
  582. int f;    /* default flag */
  583. int n;    /* numeric argument */
  584.  
  585. {
  586.     WINDOW *wp;    /* current window being examined */
  587.     WINDOW *nextwp;    /* next window to scan */
  588.     WINDOW *lastwp;    /* last window scanned */
  589.     int lastline;    /* screen line of last line of current window */
  590.  
  591.     /* if the command defaults, assume the largest */
  592.     if (f == FALSE)
  593.         n = term.t_mrow + 1;
  594.  
  595.     /* make sure it's in range */
  596.     if (n < 3 || n > term.t_mrow + 1) {
  597.         mlwrite("%%Screen size out of range");
  598.         return(FALSE);
  599.     }
  600.  
  601.     if (term.t_nrow == n - 1)
  602.         return(TRUE);
  603.     else if (term.t_nrow < n - 1) {
  604.  
  605.         /* go to the last window */
  606.         wp = wheadp;
  607.         while (wp->w_wndp != NULL)
  608.             wp = wp->w_wndp;
  609.  
  610.         /* and enlarge it as needed */
  611.         wp->w_ntrows = n - wp->w_toprow - 2;
  612.         wp->w_flag |= WFHARD|WFMODE;
  613.  
  614.     } else {
  615.  
  616.         /* rebuild the window structure */
  617.         nextwp = wheadp;
  618.         wp = NULL;
  619.         lastwp = NULL;
  620.         while (nextwp != NULL) {
  621.             wp = nextwp;
  622.             nextwp = wp->w_wndp;
  623.     
  624.             /* get rid of it if it is too low */
  625.             if (wp->w_toprow > n - 2) {
  626.  
  627.                 /* save the point/mark if needed */
  628.                 if (--wp->w_bufp->b_nwnd == 0) {
  629.                     wp->w_bufp->b_dotp = wp->w_dotp;
  630.                     wp->w_bufp->b_doto = wp->w_doto;
  631.                     wp->w_bufp->b_markp = wp->w_markp;
  632.                     wp->w_bufp->b_marko = wp->w_marko;
  633.                 }
  634.     
  635.                 /* update curwp and lastwp if needed */
  636.                 if (wp == curwp)
  637.                     curwp = wheadp;
  638.                     curbp = curwp->w_bufp;
  639.                 if (lastwp != NULL)
  640.                     lastwp->w_wndp = NULL;
  641.  
  642.                 /* free the structure */
  643.                 free((char *)wp);
  644.                 wp = NULL;
  645.  
  646.             } else {
  647.                 /* need to change this window size? */
  648.                 lastline = wp->w_toprow + wp->w_ntrows - 1;
  649.                 if (lastline >= n - 2) {
  650.                     wp->w_ntrows = n - wp->w_toprow - 2;
  651.                     wp->w_flag |= WFHARD|WFMODE;
  652.                 }
  653.             }
  654.     
  655.             lastwp = wp;
  656.         }
  657.     }
  658.  
  659.     /* screen is garbage */
  660.     term.t_nrow = n - 1;
  661.     sgarbf = TRUE;
  662.     return(TRUE);
  663. }
  664.  
  665. newwidth(f, n)    /* resize the screen, re-writing the screen */
  666.  
  667. int f;    /* default flag */
  668. int n;    /* numeric argument */
  669.  
  670. {
  671.     /* if the command defaults, assume the largest */
  672.     if (f == FALSE)
  673.         n = term.t_mcol;
  674.  
  675.     /* make sure it's in range */
  676.     if (n < 10 || n > term.t_mcol) {
  677.         mlwrite("%%Screen width out of range");
  678.         return(FALSE);
  679.     }
  680.  
  681.     /* otherwise, just re-width it (no big deal) */
  682.     term.t_ncol = n;
  683.     term.t_margin = n / 10;
  684.     term.t_scrsiz = n - (term.t_margin * 2);
  685.     curwp->w_flag |= WFHARD | WFMOVE;
  686.     sgarbf = TRUE;
  687.     return(TRUE);
  688. }
  689.